package org.mbds.wolf.db;

/**
 *
 * @author amles_000
 *
 */
public class DataValue extends AtomicData {

    public final static short MAX_HISTORY = 10;
    private short historyCount = 0;
    private Object[] history = new Object[MAX_HISTORY];

    /**
     * Constructor
     * @param value
     * @param id 
     */
    public DataValue(short id, byte[] value) {
        super(id, value);
    }

    /**
     * delete
     * @return boolean
     */
    boolean delete() {
        if (!isDeleted) {
            isDeleted = true;
            return true;
        }  
        return false;
    }
    /**
     * history
     * @return Object[]
     */
    Object[] history() {
        return history;
    }
    /**
     * updateValue
     * @param value
     * @return boolean
     */
    boolean updateValue(byte[] value) {
        if (!isDeleted) {
            if (historyCount + 1 > MAX_HISTORY) {
                for (short i=1;i<history.length;i++) {
                    history[i-1]=history[i];
                }
            } else historyCount++;
            history[historyCount] = this.value;
            this.value = value;
            return true;
        }
        return false;
    }
}
